<include file="Inc/header" />
<script type="text/javascript" src="__PUBLIC__/scripts/sisyphus.min.js"></script>
<script type="text/javascript">
    function submitFun(act)
    {
        form1.action.value = act;
        form1.submit();
    }
</script>
<script>
    $( function() {
        $( "#tab1" ).sisyphus();
    } );
</script>

        <div class="content-box">
            <!-- Start Content Box -->
            <div class="content-box-header">
                <h3>价值：{$rest_total_show}</h3>

                    <div class="clear"></div>
            </div>
            <!-- End .content-box-header -->
            <div class="content-box-content">
                <div class="tab-content default-tab" id="tab1">

                    <table>
                        <thead>
                        <tr>
                            <!--th>
                                <input class="check-all" type="checkbox"/>
                            </th-->
                            <th width="8%">序号</th>
                            <th width="8%">类别</th>
                            <th width="8%">入库时间</th>
                            <th width="8%">名称</th>
                            <th width="8%">单价</th>
                            <th width="8%">单位</th>
                            <th width="12%">剩余价值</th>
                            <th width="10%">剩余数量</th>
                            <th width="10%">出库数量</th>
                            <th width="16%">出库总价</th>
                        </tr>
                        </thead>

                        <form name='form1' action="{:U('Admin/Kucun/chuku')}" method="post" id="form1">
                        <tbody>
                        <volist name="stus" id="user">
                            <tr>

                                <!--td>
                                    <input type="checkbox"/>
                                </--td-->
                                <td>{$user['id']}</td>
                                <td>{$user['sort']}</td>
                                <td>{$user['date']}</td>
                                <td>{$user['name']}</td>
                                <td>{$user['price']}</td>
                                <td>{$user['unit']}</td>
                                <td>{$user['rest_total']}</td>
                                <td style="color: #990000;text-align: right;">{$user['rest_number']}</td>
                                <td>
                                    <input name="detail[{$user['id']}][id]" class="ck_id" type="hidden" value="{$user['id']}">
                                    <input name="detail[{$user['id']}][gid]" class="ck_id" type="hidden" value="{$user['gid']}">
                                    <input name="detail[{$user['id']}][gname]" class="ck_id" type="hidden" value="{$user['name']}">
                                    <input name="detail[{$user['id']}][unit]" class="ck_id" type="hidden" value="{$user['unit']}">
                                    <input name="detail[{$user['id']}][sort]" class="ck_id" type="hidden" value="{$user['sort']}">
                                    <input name="detail[{$user['id']}][price]" class="ck_price" type="hidden" value="{$user['price']}">
                                    <input name="detail[{$user['id']}][rest_number]" class="ck_rest_number" type="hidden" value="{$user['rest_number']}">
                                    <input name="detail[{$user['id']}][ck_num]" class="ck_num" type="number" style="width: 80px;">
                                </td>
                                <td><input name="detail[{$user['id']}][ck_total]" class="ck_total" type="text" style="width: 80px;"></td>
                            </tr>
                        </volist>
                        <tr>
                            <td style="text-align: right;">菜单：</td><td colspan="2">
                                <select name="caidan_menu" id="caidan_menu" class="search form-control zhangben" style="width: 180px;">
                                    <option value="0">选择菜单</option>
                                    <volist name="menu_array" id="class">
                                        <option value="{$class['name']}">{$class['name']}</option>
                                    </volist>
                                    <option value="结转下学期">结转下学期</option>
                                </select><input name="chukuren" type="hidden" value="{$school_info.chukuren}">
                               </td>
                            <td colspan="2">学生数：<input name="student_number" id="student_number" type="text" value="{$student_number}" style="width: 80px;"></td>
                            <td colspan="2">合计总价：<input name="ck_all_sum" id="ck_all_sum" style="width: 100px;" readonly></td>
                            <td colspan="2">餐均价：<input name="can_avg" id="can_avg" style="width: 80px;" readonly></td>
                            <td><span name="出库" ID="ck" class="button1">出库</span></td>
                        </tr>
                        <tr>
                            <td colspan="3">
                            <input class="search form-control input-group date datepicker" name="date"  data-provide="datepicker"  placeholder="日期" value="{$date}"/>
                        </td>
                        <td style="text-align: right;">
                           <label>单据号：</label>
                        </td>
                        <td colspan="4">
                           <input name="danjuhao" type="text"  class="search form-control" style="width: 100px;" value="{$danjuhao}"/>
                        </td>
                            <td colspan="2"><select name="memo" class="search form-control">
                                <option value="食用" selected="selected">食用</option>
                                <option value="结转下期">结转下期</option>
                            </select>
                            </td>
                        </tr>
                        </tbody>
                       </form>
                    </table>
                </div>
                <!-- End #tab1 -->

            </div>
            <!-- End .content-box-content -->
        </div>
<script>
    jQuery(function($){
        total_money();
        //计算总金额函数
        function total_money() {
            var money=0;
            $(".ck_total").each(function(){
                var zmoney=$(this).val();
                zmoney = zmoney * 10;
                money+=parseInt(zmoney);
            });
            //  alert(money);
            money = (money / 10).toFixed(1);
            var student_number=$("#student_number").val();   //读取学生数
            avg_money = (money / student_number).toFixed(2);
            $("#ck_all_sum").val(money); //总金额自动填入
            $("#can_avg").val(avg_money); //总金额自动填入
        }
        //计算功能
        function accMul(arg1,arg2){
            var m=0,s1=arg1.toString(),s2=arg2.toString();
            try{m+=s1.split(".")[1].length}catch(e){}
            try{m+=s2.split(".")[1].length}catch(e){}
            return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
        }
        //离开输入框提示
        $('.ck_num').live("blur",(function() {
            var num = ($(this).val());


            var price = $(this).parent().parent().find(".ck_price").val();  //价格
            var rest_number = $(this).parent().parent().find(".ck_rest_number").val();  //剩余数量

            if(parseFloat(num)<0){
                alert('出库不能为负数');
                num = 0;
                $(this).val(0);
                //     $(this).parent().parent().find(".ck_total").val(0); //总金额自动填入
            }


            if(parseFloat(num)>parseFloat(rest_number)){
                alert('出库数量不能大于剩余数量');
                $(this).val(rest_number);
                num = rest_number;
                // $(this).focus();
                // return false;
            }
            zongjine = accMul(num, price);
            zongjine=zongjine.toFixed(1);
            $(this).parent().parent().find(".ck_total").val(zongjine); //总金额自动填入
            total_money();
        }));

        //离开输入框提示
        $('#student_number').live("blur",(function() {
            var stu_num = $(this).val();
            var ck_all_sum=$("#ck_all_sum").val(); //总金额
            avg_money=(ck_all_sum/stu_num).toFixed(2);
            $("#can_avg").val(avg_money); //总金额自动填入
        }));

        $('#ck').live("click",(function() {
            var money=$("#ck_all_sum").val();
            var can_avg=$("#can_avg").val();
            var caidan_menu=$("#caidan_menu").val();
            if(parseInt(money)==0 || parseInt(can_avg)==0 || parseInt(caidan_menu)==0){
                alert("菜单未选择或是没有出库商品，禁止提交！");
            }else{
                localStorage.clear(); //清除缓存
                form1.submit();
            }
        }));
    });
</script>
        <include file="Inc/footer"/>
